package com.qcby.controller;

import com.qcby.dao.AdminDao;
import com.qcby.entity.Admin;
import com.qcby.entity.Result;
import com.qcby.service.AdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.apache.http.HttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "管理员接口")
@Controller
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @ApiModelProperty("后端管理员登录")
    @PostMapping("/login")
    @ResponseBody
    public Result AdminLogin(Admin admin, HttpServletRequest request){
        return Result.success(adminService.SelectAdmin(admin,request));
    }
    @ApiModelProperty("取消登录者的信息")
    @GetMapping("/logout")
    public Result delAdminInfo(HttpServletRequest request){
        request.getSession().removeAttribute("admin");
        return Result.success();
    }
}
